home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / PRIMITIV / FLAT / COMFLAT.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  7.5 KB  |  271 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: COMFlat.cpp 1.9 1997/06/20 22:30:12 damien Exp $ */
  3.  
  4. ////////////////////////////////////////////////////////////////////////
  5. //   Geometric Primitive Example : Flat surface                       //
  6. //--------------------------------------------------------------------//
  7. //   Implementation of the Flat Interface                           //
  8. //////////////////////////////////////////////////////////////////////// 
  9.  
  10. #ifndef __COMFLAT__
  11. #include "COMFlat.h"
  12. #endif
  13.  
  14. #ifndef __3DCOFAIL__
  15. #include "3DCoFail.h"
  16. #endif
  17.  
  18. #ifndef __ISHFMESH__
  19. #include "IShFMesh.h"
  20. #endif 
  21.  
  22. #ifndef __I3DSHUTI__
  23. #include "I3DShUti.h"
  24. #endif 
  25.          
  26. // Constructor / Destructor of the C++ Object :
  27. Flat::Flat() {
  28.   fCRef=0; // Reference Counter
  29.   }
  30.   
  31. Flat::~Flat() {
  32.   global_count_Obj--; 
  33.   }
  34.   
  35. // IUnknown Interface :
  36. HRESULT Flat::QueryInterface(THIS_ REFIID riid,LPVOID FAR* ppvObj) {
  37.   *ppvObj=NULL;
  38.   
  39.   // The Flat knows the interfaces of the parent Objects
  40.   if (IsEqualIID(riid, IID_IUnknown))
  41.     *ppvObj=(IUnknown*)(I3DExGeometricPrimitive*)this;
  42.   else if (IsEqualIID(riid, IID_I3DExGeometricPrimitive))
  43.     *ppvObj=(I3DExGeometricPrimitive*)this;
  44.   else if (IsEqualIID(riid, IID_I3DExDataExchanger))
  45.     *ppvObj=(I3DExDataExchanger*)this;
  46.   else if (IsEqualIID(riid, IID_I3DExtension))
  47.     *ppvObj=(I3DExtension*)this;
  48.     
  49.   // we must add reference if we return an interface
  50.   if (*ppvObj!=NULL) {
  51.     ((LPUNKNOWN)*ppvObj)->AddRef();
  52.     return NOERROR;
  53.     }
  54.   else {
  55.     return ResultFromScode(E_NOINTERFACE);
  56.     }
  57.   }
  58.  
  59. ULONG Flat::AddRef(THIS) {
  60.   return fCRef++;
  61.   }
  62.   
  63. ULONG Flat::Release(THIS) {
  64.   ULONG UnreleaseObject=fCRef--;
  65.   
  66.   if (fCRef==0)
  67.      delete this; // No reference left, so destroy the object
  68.   
  69.   return UnreleaseObject;
  70.   // local variable used, because fCRef can be destroyed before.
  71.   }
  72.   
  73. // I3DExtension methods :
  74. I3DExtension* Flat::Clone(THIS) {
  75.   Flat* theClone = new Flat;
  76.   if (theClone) {
  77.     theClone->AddRef();
  78.     }                               
  79.   return (I3DExtension*)theClone;
  80.   }   
  81.  
  82. HRESULT Flat::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
  83.   InitCoFailure(shellUtilities);
  84.   return NOERROR;
  85.   }
  86.  
  87. // I3DExDataExchanger methods :
  88. ExtensionDataMap* Flat::GetExtensionDataMap(THIS) {
  89.   return NULL;
  90.   }               
  91.   
  92. void* Flat::GetExtensionDataBuffer(THIS) {
  93.   return NULL;
  94.   }
  95.   
  96. HRESULT Flat::ExtensionDataChanged(THIS) {
  97.   return NOERROR;
  98.   }
  99.  
  100. HRESULT Flat::HandleEvent(THIS_ ULONG SourceID) {
  101.   return ResultFromScode(E_NOTIMPL);
  102.   }
  103.  
  104. short Flat::GetResID(THIS) {
  105.   return -1;  // always return -1, if you do not have a view
  106.   }
  107.   
  108. // I3DExGeometricPrimitive methods
  109. // -- Geometry calls
  110. HRESULT Flat::EnumPatches(THIS_ EnumPatchesCallback callback, void* privData) {
  111.   return ResultFromScode(E_NOTIMPL);
  112.   }
  113.   
  114. HRESULT Flat::EnumFacets(THIS_ EnumFacetsCallback callback, void* privData, NUM3D fidelity) {
  115.   FACET3D  Facet;
  116.     NUM3D    size = 10.0; 
  117.     VECTOR3D normal;
  118.  
  119.     normal[0]=0.0;
  120.   normal[1]=0.0;
  121.     normal[2]=1.0;
  122.  
  123.     Facet.fUVSpace=0;
  124.     Facet.fVertices[0].fVertex[0]=-size;
  125.     Facet.fVertices[0].fVertex[1]=-size;
  126.     Facet.fVertices[0].fVertex[2]=0.0;
  127.     Facet.fVertices[0].fUV[0]=0.0;
  128.     Facet.fVertices[0].fUV[1]=0.0;
  129.     Facet.fVertices[0].fNormal[0]=normal[0];
  130.     Facet.fVertices[0].fNormal[1]=normal[1];
  131.     Facet.fVertices[0].fNormal[2]=normal[2];
  132.  
  133.     // Common points of the 2 facets
  134.     Facet.fVertices[1].fVertex[0]=size;
  135.     Facet.fVertices[1].fVertex[1]=-size;
  136.     Facet.fVertices[1].fVertex[2]=0.0;
  137.     Facet.fVertices[1].fUV[0]=size*2.0;
  138.     Facet.fVertices[1].fUV[1]=0.0;
  139.     Facet.fVertices[1].fNormal[0]=normal[0];
  140.     Facet.fVertices[1].fNormal[1]=normal[1];
  141.     Facet.fVertices[1].fNormal[2]=normal[2];
  142.  
  143.     Facet.fVertices[2].fVertex[0]=-size;
  144.     Facet.fVertices[2].fVertex[1]=size;
  145.     Facet.fVertices[2].fVertex[2]=0.0;
  146.   Facet.fVertices[2].fUV[0]=0.0;
  147.     Facet.fVertices[2].fUV[1]=size*2.0;
  148.     Facet.fVertices[2].fNormal[0]=normal[0];
  149.     Facet.fVertices[2].fNormal[1]=normal[1];
  150.     Facet.fVertices[2].fNormal[2]=normal[2];
  151.  
  152.     // First Facet
  153.   callback(&Facet,privData);
  154.  
  155.     Facet.fVertices[0].fVertex[0]=size;
  156.     Facet.fVertices[0].fVertex[1]=size;
  157.     Facet.fVertices[0].fVertex[2]=0.0;
  158.     Facet.fVertices[0].fUV[0]=size*2.0;
  159.     Facet.fVertices[0].fUV[1]=size*2.0;
  160.     
  161.     // Second Facet
  162.   callback(&Facet,privData);
  163.   
  164.   return NOERROR;
  165.     }              
  166.     
  167. void AccuFacet(FACET3D* facet, void* accu) {
  168.     ((IShFacetMeshAccumulator*)accu)->AddFacet(facet);
  169.     }
  170.  
  171. HRESULT Flat::GetNbrLOD(short &nbrLod) {
  172.   return ResultFromScode(E_NOTIMPL);
  173.     }
  174.  
  175. HRESULT Flat::GetLOD(short lodIndex, NUM3D &lod) {
  176.   return ResultFromScode(E_NOTIMPL);
  177.     }
  178.  
  179. HRESULT Flat::MakeFacetMesh(short index, FacetMesh &amesh) {
  180.     IShFacetMeshAccumulator* accu;
  181.     gShellUtilities->CoCreateInstance(CLSID_StandardFacetMeshAccumulator, NULL, CLSCTX_INPROC_SERVER, IID_IShFacetMeshAccumulator, (LPVOID*)&accu);
  182.     EnumFacets(AccuFacet, accu, 0);
  183.     accu->MakeFacetMesh(amesh);
  184.     accu->Release();
  185.     return S_OK;
  186.     }
  187.  
  188. HRESULT Flat::MakeFacetMesh(NUM3D lod, FacetMesh &amesh) {
  189.     return MakeFacetMesh((short)0, amesh);
  190.     }
  191.  
  192. // Give the boundary Box
  193. HRESULT Flat::GetBBox(THIS_ BOX3D* bbox) {
  194.     bbox->fMin[0]=-10.0;
  195.   bbox->fMax[0]=10.0;
  196.   bbox->fMin[1]=-10.0;
  197.   bbox->fMax[1]=10.0;
  198.   bbox->fMin[2]=0.0;
  199.   bbox->fMax[2]=0.0;
  200.   return NOERROR;
  201.     }
  202.   
  203. // -- Shading calls
  204. ULONG Flat::GetUVSpaceCount(THIS) {
  205.   return 1; // the star is describe with only 1 UV-Space
  206.     }
  207.  
  208. HRESULT Flat::GetUVSpace(THIS_ ULONG uvSpaceID, UVSpaceInfo* uvSpaceInfo) {
  209.     NUM3D size;
  210.   if (uvSpaceID == 0) { 
  211.       size = 10.0;
  212.     uvSpaceInfo->fMin[0] = 0.0; // u coordinate goes from 0 to 10*2
  213.     uvSpaceInfo->fMax[0] = size*2.0;
  214.     uvSpaceInfo->fMin[1] = 0.0; // v coordinate goes from 0 to 10*2
  215.     uvSpaceInfo->fMax[1] = size*2.0;
  216.     uvSpaceInfo->fWraparound[0] = FALSE;  // No Wrap around
  217.     uvSpaceInfo->fWraparound[1] = FALSE;
  218.     /*uvSpaceInfo->fIsFlatSurface = TRUE;  // the surface is flat
  219.         // Flat transformation
  220.         // - Point to UV
  221.         //   --  Offset to have (0,0) in the corner of the surface
  222.     uvSpaceInfo->fUVOffset[0]=size;
  223.       uvSpaceInfo->fUVOffset[1]=size;
  224.         //   --  u projector
  225.         uvSpaceInfo->fProjU[0]=1.0;
  226.         uvSpaceInfo->fProjU[1]=0.0;
  227.         uvSpaceInfo->fProjU[2]=0.0;
  228.         //   --  v projector
  229.         uvSpaceInfo->fProjV[0]=0.0;
  230.         uvSpaceInfo->fProjV[1]=1.0;
  231.         uvSpaceInfo->fProjV[2]=0.0;
  232.         // - UV to Point
  233.         //   --  No Offset
  234.     uvSpaceInfo->fOffset[0]=-size;
  235.       uvSpaceInfo->fOffset[1]=-size;
  236.         //   --  x projector
  237.         uvSpaceInfo->fProjX[0]=1.0;
  238.         uvSpaceInfo->fProjX[1]=0.0;
  239.         //   --  y projector
  240.         uvSpaceInfo->fProjY[0]=0.0;
  241.         uvSpaceInfo->fProjY[1]=1.0;
  242.         //   --  z projector
  243.         uvSpaceInfo->fProjZ[0]=0.0;
  244.         uvSpaceInfo->fProjZ[1]=0.0;*/
  245.  
  246.         }
  247.   return NOERROR;
  248.     }
  249.   
  250. // We use the default interpolation method to get all the coordinate of a point in UV Coordinates
  251. HRESULT Flat::UV2XYZ(THIS_ VECTOR2D* uv, ULONG uvSpaceID, VECTOR3D* resultPosition, BOOLEAN* inUVSpace) {
  252.   return ResultFromScode(E_NOTIMPL);
  253.     }
  254.  
  255. // -- Ray Tracing calls
  256. HRESULT Flat::RayHit(THIS_ BOOLEAN* didHit, Ray3D* aR, RayHitParameters* RayHitParams, RayHit3D* hit) {
  257.   return ResultFromScode(E_NOTIMPL);
  258.   }
  259.   
  260. HRESULT Flat::GetRayHitDetails(THIS_ RayHit3D* hit) {
  261.   return ResultFromScode(E_NOTIMPL);
  262.   }
  263.   
  264. HRESULT Flat::RayAllHits(THIS_ Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, RayHitCallback callback, void* privData) {
  265.   return ResultFromScode(E_NOTIMPL);
  266.   }
  267.   
  268.  
  269.  
  270.  
  271.